package com.atguigu.mvc.controller;

import com.atguigu.mvc.bean.User;
import org.springframework.http.RequestEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @版本： V5.1.0
 * @版权： Copyright @ 2025 广东广昱信息科技有限公司版权所有
 * @作者： 广东广昱信息科技有限公司
 * @日期： 2025-06-02 14:16
 */
@Controller
public class HttpController {

    @RequestMapping("/testRequestBody")
     public String testRequestBody(@RequestBody String requestBody){
        System.out.println("requestBody:"+requestBody);
        return "success";
    }

    @RequestMapping("/testRequestEntity")
    public String testRequestEntity(RequestEntity requestEntity){
        //当前requestEntity表示整个请求报文的信息
        System.out.println("请求头:"+requestEntity.getHeaders());
        System.out.println("请求体:"+requestEntity.getBody());
        return "success";
    }

     @RequestMapping("/testResponse")
     public void testResponse(HttpServletResponse response) throws IOException {
        response.getWriter().println( "hello,Response");
     }
     @RequestMapping("/testResponseBody")
     @ResponseBody
     public String testResponseBody(){
        return "success";
    }

     @RequestMapping("/testResponseUser")
     @ResponseBody
      public User testResponseUser(){
        return new User(1001,"admin","123456",23,"男");
    }
    @RequestMapping("/testAxios")
    @ResponseBody
    public String testAxios(String username, String password){
        System.out.println("username:"+username+",password:"+password);
        return "hello,ajax";
    }

}
